import React from 'react'
import { useState } from 'react'

const StateTest = () => {
    const [num, setNum] = useState(0)
    const [obj, setObj] = useState({id: 1})

    return (
        <div>
            <span>num的值:{num}</span>
            <button onClick={() => {setNum(num + 1)}}>+1</button>
            <span>{JSON.stringify(obj)}</span>
            <button onClick={() => {setObj((preObj) => ({...preObj, ...{id: 2, name: 'kaho'}}))}}>change obj</button>
        </div>
    )
}

export default StateTest
